package com.yunfei.springbootgoods.handler;


import com.yunfei.springbootgoods.dto.Result;
import com.yunfei.springbootgoods.exception.MyException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class ExceptionController {

    @ResponseBody
    @ExceptionHandler(value = {MyException.class})
    public Result commonException(MyException e){

        e.printStackTrace();

        Result result = new Result();
        result.setCode(e.getCode());
        result.setMsg(e.getMsg());
        return result;

    }

}
